﻿#Region "Copyright"
'————————————————————————————————————————
'	创建人员(Creator)    ：Huangyd
'	创建日期(Date)       ：2012-07-14
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'	Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Reflection

''' <summary>
''' 控件辅助类
''' Author  ajayumi
''' Date    2010-010-20
''' </summary>
Public Class ControlHelper

#Region "共享方法"

#Region "SetText"
    Public Shared Sub SetText(ByVal control As Label, ByVal text As String)
        If control.InvokeRequired = True Then
            control.Invoke(New Action(Of Label, String)(AddressOf SetText), New Object() {control, text})
        Else
            control.Text = text
        End If
    End Sub

    Public Shared Sub SetText(ByVal control As TextBox, ByVal text As String)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of TextBox, String)(AddressOf SetText), New Object() {control, text})
        Else
            control.Text = text
        End If
    End Sub

    Public Shared Sub SetText(ByVal control As RichTextBox, ByVal text As String)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of RichTextBox, String)(AddressOf SetText), New Object() {control, text})
        Else
            control.Text = text
        End If
    End Sub
#End Region

#Region "AppendText"
    Public Shared Sub AppendText(ByVal control As TextBox, ByVal text As String)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of TextBox, String)(AddressOf AppendText), New Object() {control, text})
        Else
            control.AppendText(text)
        End If
    End Sub

    Public Shared Sub AppendText(ByVal control As RichTextBox, ByVal text As String)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of RichTextBox, String)(AddressOf AppendText), New Object() {control, text})
        Else
            control.AppendText(text)
        End If
    End Sub
#End Region

#Region "SetEnabled"

    Public Shared Sub SetEnabled(ByVal control As Button, ByVal vaule As Boolean)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of Button, Boolean)(AddressOf SetEnabled), New Object() {control, vaule})
        Else
            control.Enabled = vaule
        End If
    End Sub

    Public Shared Sub SetEnabled(ByVal control As TextBox, ByVal vaule As Boolean)
        If control.InvokeRequired Then
            control.Invoke(New Action(Of TextBox, Boolean)(AddressOf SetEnabled), New Object() {control, vaule})
        Else
            control.Enabled = vaule
        End If
    End Sub

#End Region

#Region "SetVisible"
    Public Shared Sub SetVisible(ByVal control As ProgressBar, ByVal value As Boolean)
        If control.InvokeRequired = True Then
            control.Invoke(New Action(Of ProgressBar, Boolean)(AddressOf SetVisible), New Object() {control, value})
        Else
            control.Visible = value
        End If
    End Sub


#End Region

#Region "SetImage"
    Public Shared Sub SetImage(ByVal control As PictureBox, ByVal stream As System.IO.Stream)
        If control.InvokeRequired = True Then
            control.Invoke(New Action(Of PictureBox, System.IO.Stream)(AddressOf SetImage), New Object() {control, stream})
        Else
            control.Image = Image.FromStream(stream)
        End If
    End Sub
#End Region

#Region "SetValue"

#End Region

    ''' <summary>
    ''' 设置控件的双缓冲方式
    ''' </summary>
    ''' <param name="control"></param>
    ''' <param name="value"></param>
    ''' <remarks></remarks>
    Public Shared Sub DoubleBuffered(ByVal control As Windows.Forms.Control, ByVal value As Boolean)
        Dim _Type As Type = control.GetType()
        Dim _PropertyInfo As PropertyInfo = _Type.GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
        _PropertyInfo.SetValue(control, value, Nothing)
    End Sub

#End Region

#Region "Template"

    'ajayumi.Component.ProgressBar.VBasic.ProgressBar-----------------------------------------------------------------------------

    '''' <summary>
    '''' 设置进度条进度值
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="value"></param>
    '''' <remarks></remarks>
    'Private Sub setValue(ByVal control As ajayumi.Component.ProgressBar.VBasic.ProgressBar, ByVal value As Integer)
    '    If Me.ProgressBar1.InvokeRequired Then
    '        Me.ProgressBar1.Invoke(New Action(Of ajayumi.Component.ProgressBar.VBasic.ProgressBar, Integer)(AddressOf Me.setValue), New Object() {control, value})
    '    Else
    '        control.Value = value
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置进度条样式
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="style"></param>
    '''' <remarks></remarks>
    'Private Sub setStyle(ByVal control As ajayumi.Component.ProgressBar.VBasic.ProgressBar, ByVal style As ProgressBarStyle)
    '    If Me.ProgressBar1.InvokeRequired Then
    '        Me.ProgressBar1.Invoke(New Action(Of ajayumi.Component.ProgressBar.VBasic.ProgressBar, ProgressBarStyle)(AddressOf Me.setStyle), New Object() {control, style})
    '    Else
    '        control.Style = style
    '    End If
    'End Sub


    '''' <summary>
    '''' 设置进度条文本值
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="text"></param>
    '''' <remarks></remarks>
    'Private Sub setText(ByVal control As ajayumi.Component.ProgressBar.VBasic.ProgressBar, ByVal text As String)
    '    If Me.ProgressBar1.InvokeRequired Then
    '        Me.ProgressBar1.Invoke(New Action(Of ajayumi.Component.ProgressBar.VBasic.ProgressBar, String)(AddressOf Me.setText), New Object() {control, text})
    '    Else
    '        control.CustomText = text
    '    End If
    'End Sub

    'ajayumi.Component.ProgressBar.VBasic.ProgressBar-----------------------------------------------------------------------------


    '''' <summary>
    '''' 设置状态栏进度条进度值
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="value"></param>
    '''' <remarks></remarks>
    'Private Sub setValue(ByVal control As ToolStripProgressBar, ByVal value As Integer)
    '    If Me.StatusStrip1.InvokeRequired Then
    '        Me.StatusStrip1.Invoke(New Action(Of ToolStripProgressBar, Integer)(AddressOf Me.setValue), New Object() {control, value})
    '    Else
    '        control.Value = value
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置状态栏标签的文本值
    '''' </summary>
    '''' <param name="control">状态栏标签控件</param>
    '''' <param name="text">文本值</param>
    'Private Sub setText(ByVal control As ToolStripStatusLabel, ByVal text As String)
    '    If Me.StatusStrip1.InvokeRequired Then
    '        Me.StatusStrip1.Invoke(New Action(Of ToolStripStatusLabel, String)(AddressOf Me.setText), New Object() {control, text})
    '    Else
    '        control.Text = text
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置状态栏标签的可见性
    '''' </summary>
    '''' <param name="control">状态栏标签控件</param>
    '''' <param name="value">是否可见</param>
    'Private Sub setVisible(ByVal control As ToolStripStatusLabel, ByVal value As Boolean)
    '    If Me.StatusStrip1.InvokeRequired Then
    '        Me.StatusStrip1.Invoke(New Action(Of ToolStripStatusLabel, String)(AddressOf Me.setVisible), New Object() {control, value})
    '    Else
    '        control.Visible = value
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置状态栏进度条的可见性
    '''' </summary>
    '''' <param name="control">状态栏进度条控件</param>
    '''' <param name="value">是否可见</param>
    'Private Sub setVisible(ByVal control As ToolStripProgressBar, ByVal value As Boolean)
    '    If Me.StatusStrip1.InvokeRequired Then
    '        Me.StatusStrip1.Invoke(New Action(Of ToolStripProgressBar, String)(AddressOf Me.setVisible), New Object() {control, value})
    '    Else
    '        control.Visible = value
    '    End If
    'End Sub


    '''' <summary>
    '''' 设置工具条中标签的文本值
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="text"></param>
    '''' <remarks></remarks>
    'Private Sub setText(ByVal control As ToolStripLabel, ByVal text As String)
    '    If Me.BindingNavigator1.InvokeRequired Then
    '        Me.BindingNavigator1.Invoke(New Action(Of ToolStripLabel, String)(AddressOf Me.setText), New Object() {control, text})
    '    Else
    '        Me.tslbDownloadInfo.Text = text
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置单元格文本值
    '''' </summary>
    '''' <param name="subItem"></param>
    '''' <param name="text"></param>
    '''' <remarks></remarks>
    'Private Sub setText(ByVal subItem As ListViewSubItem, ByVal text As String)
    '    If Me.ListView.InvokeRequired Then
    '        Me.ListView.Invoke(New Action(Of ListViewSubItem, String)(AddressOf setText), New Object() {subItem, text})
    '    Else
    '        subItem.Text = text
    '    End If
    'End Sub

    '''' <summary>
    '''' 移除项
    '''' </summary>
    '''' <param name="item"></param>
    '''' <remarks></remarks>
    'Private Sub removeItem(ByVal item As lviResource)
    '    If Me.ListView.InvokeRequired Then
    '        Me.ListView.Invoke(New Action(Of lviResource)(AddressOf removeItem), New Object() {item})
    '    Else
    '        Me.ListView.Items.Remove(item)
    '    End If
    'End Sub

    '''' <summary>
    '''' 设置工具条中按钮是否可用
    '''' </summary>
    '''' <param name="control"></param>
    '''' <param name="value"></param>
    '''' <remarks></remarks>
    'Private Sub setEnable(ByVal control As ToolStripButton, ByVal value As Boolean)
    '    If Me.ToolStrip1.InvokeRequired Then
    '        Me.ToolStrip1.Invoke(New Action(Of ToolStripButton, Boolean)(AddressOf Me.setEnable), New Object() {control, value})
    '    Else
    '        control.Enabled = value
    '    End If
    'End Sub
#End Region

End Class
